/**
 *  Copyright 2002-2009 the original author or authors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package foo.bar.blog.web.action.general;

import foo.bar.blog.core.domain.Blog;
import foo.bar.blog.core.services.BlogService;
import foo.bar.blog.utils.DateList;
import foo.bar.blog.web.action.BaseActionBean;
import foo.bar.blog.web.action.MonthEnum;
import foo.bar.blog.web.extension.BlogTypeConverter;
import foo.bar.blog.web.extension.CalendarTypeConverter;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.integration.spring.SpringBean;
import net.sourceforge.stripes.validation.Validate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.perf4j.aop.Profiled;

import java.util.Calendar;
import java.util.Date;

/**
 * Calendaring related actions :-
 *
 * @author tmjee
 * @version $Date: 2009-03-14 06:53:07 +0000 (Sat, 14 Mar 2009) $ $Id$
 */
public class CalendarActionBean extends BaseActionBean {


    private static final Log LOG = LogFactory.getLog(CalendarActionBean.class);


    public static final String VIEW = "/calendar.jsp";


    @Validate(converter = BlogTypeConverter.class, on={"view"})
    private Blog blog;


    @Validate(converter = CalendarTypeConverter.class, on="view")
    private foo.bar.blog.web.action.Calendar calendar;


    private Day monday_1;
    private Day tuesday_1;
    private Day wednesday_1;
    private Day thursday_1;
    private Day friday_1;
    private Day saturday_1;
    private Day sunday_1;
    private Day monday_2;
    private Day tuesday_2;
    private Day wednesday_2;
    private Day thursday_2;
    private Day friday_2;
    private Day saturday_2;
    private Day sunday_2;
    private Day monday_3;
    private Day tuesday_3;
    private Day wednesday_3;
    private Day thursday_3;
    private Day friday_3;
    private Day saturday_3;
    private Day sunday_3;
    private Day monday_4;
    private Day tuesday_4;
    private Day wednesday_4;
    private Day thursday_4;
    private Day friday_4;
    private Day saturday_4;
    private Day sunday_4;
    private Day monday_5;
    private Day tuesday_5;
    private Day wednesday_5;
    private Day thursday_5;
    private Day friday_5;
    private Day saturday_5;
    private Day sunday_5;


    private BlogService blogService;


    /**
     * Returns portion of the page, displaying the calendar, dates with blog entries will be highlighted,
     * clickable previous and next day etc.
     *
     * Input - calendar
     * Output - calendar, monday_1, tuesday_1, wednesday_1, thursday_1, friday_1, saturday_1, sunday_1 ...
     *          monday_5, tuesday_5, wednesday_5, thursday_5, friday_5, saturday_5, sunday_5
     *
     * @return
     */
    @DefaultHandler
    @Profiled(tag="CalendarActionBean_view", logFailuresSeparately = true)
    public Resolution view() {


        Calendar now = Calendar.getInstance();
        now.setTime(new Date());

        // if no date was selected, we will default to a calendar showing days of the whole month
        if (calendar == null) {
            calendar = new foo.bar.blog.web.action.Calendar();
            calendar.setTimeAsNow();
        }

        Calendar startOfMonth = Calendar.getInstance();
        startOfMonth.set(Calendar.DAY_OF_MONTH, 1);
        startOfMonth.set(Calendar.MONTH, calendar.getMonth().month());
        startOfMonth.set(Calendar.YEAR, calendar.getYear());

        // a running calendar 
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.MONTH, CalendarActionBean.this.calendar.getMonth().month());
        calendar.set(Calendar.YEAR, CalendarActionBean.this.calendar.getYear());

        Calendar endOfMonth = Calendar.getInstance();
        endOfMonth.set(Calendar.DAY_OF_MONTH,  1);
        endOfMonth.set(Calendar.MONTH, CalendarActionBean.this.calendar.getMonth().month());
        endOfMonth.set(Calendar.YEAR, CalendarActionBean.this.calendar.getYear());
        endOfMonth.add(Calendar.MONTH, 1);
        endOfMonth.add(Calendar.DAY_OF_MONTH, -1);


        DateList datesWithBlogEntries = new DateList(blogService.getDatesWithBlogEntries(blog, startOfMonth.getTime(),  endOfMonth.getTime()));


        monday_1 = new Day();
        tuesday_1 = new Day();
        wednesday_1 = new Day();
        thursday_1 = new Day();
        friday_1 = new Day();
        saturday_1 = new Day();
        sunday_1 = new Day();
        monday_2 = new Day();
        tuesday_2 = new Day();
        wednesday_2 = new Day();
        thursday_2 = new Day();
        friday_2 = new Day();
        saturday_2 = new Day();
        sunday_2 = new Day();
        monday_3 = new Day();
        tuesday_3 = new Day();
        wednesday_3 = new Day();
        thursday_3 = new Day();
        friday_3 = new Day();
        saturday_3 = new Day();
        sunday_3 = new Day();
        monday_4 = new Day();
        tuesday_4 = new Day();
        wednesday_4 = new Day();
        thursday_4 = new Day();
        friday_4 = new Day();
        saturday_4 = new Day();
        sunday_4 = new Day();
        monday_5 = new Day();
        tuesday_5 = new Day();
        wednesday_5 = new Day();
        thursday_5 = new Day();
        friday_5 = new Day();
        saturday_5 = new Day();
        sunday_5 = new Day();


        while(!calendar.getTime().after(endOfMonth.getTime())) {
            int weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH);
            if (weekOfMonth == 1) {
                int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
                if (dayOfWeek == Calendar.MONDAY) {
                    monday_1.setShow(true);
                    monday_1.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    monday_1.setDate(calendar.getTime());
                    monday_1.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    monday_1.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        monday_1.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.TUESDAY) {
                    tuesday_1.setShow(true);
                    tuesday_1.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    tuesday_1.setDate(calendar.getTime());
                    tuesday_1.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    tuesday_1.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        tuesday_1.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.WEDNESDAY) {
                    wednesday_1.setShow(true);
                    wednesday_1.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    wednesday_1.setDate(calendar.getTime());
                    wednesday_1.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    wednesday_1.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        wednesday_1.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.THURSDAY) {
                    thursday_1.setShow(true);
                    thursday_1.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    thursday_1.setDate(calendar.getTime());
                    thursday_1.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    thursday_1.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        thursday_1.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.FRIDAY) {
                    friday_1.setShow(true);
                    friday_1.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    friday_1.setDate(calendar.getTime());
                    friday_1.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    friday_1.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        friday_1.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.SATURDAY) {
                    saturday_1.setShow(true);
                    saturday_1.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    saturday_1.setDate(calendar.getTime());
                    saturday_1.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    saturday_1.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        saturday_1.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.SUNDAY) {
                    sunday_1.setShow(true);
                    sunday_1.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    sunday_1.setDate(calendar.getTime());
                    sunday_1.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    sunday_1.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        sunday_1.setHasEntries(true);
                    }
                }
            }
            else if (weekOfMonth == 2) {
                int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
                if (dayOfWeek == Calendar.MONDAY) {
                    monday_2.setShow(true);
                    monday_2.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    monday_2.setDate(calendar.getTime());
                    monday_2.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    monday_2.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        monday_2.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.TUESDAY) {
                    tuesday_2.setShow(true);
                    tuesday_2.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    tuesday_2.setDate(calendar.getTime());
                    tuesday_2.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    tuesday_2.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        tuesday_2.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.WEDNESDAY) {
                    wednesday_2.setShow(true);
                    wednesday_2.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    wednesday_2.setDate(calendar.getTime());
                    wednesday_2.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    wednesday_2.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        wednesday_2.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.THURSDAY) {
                    thursday_2.setShow(true);
                    thursday_2.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    thursday_2.setDate(calendar.getTime());
                    thursday_2.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    thursday_2.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        thursday_2.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.FRIDAY) {
                    friday_2.setShow(true);
                    friday_2.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    friday_2.setDate(calendar.getTime());
                    friday_2.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    friday_2.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        friday_2.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.SATURDAY) {
                    saturday_2.setShow(true);
                    saturday_2.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    saturday_2.setDate(calendar.getTime());
                    saturday_2.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    saturday_2.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        saturday_2.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.SUNDAY) {
                    sunday_2.setShow(true);
                    sunday_2.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    sunday_2.setDate(calendar.getTime());
                    sunday_2.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    sunday_2.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        sunday_2.setHasEntries(true);
                    }
                }
            }
            else if (weekOfMonth == 3) {
                int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
                if (dayOfWeek == Calendar.MONDAY) {
                    monday_3.setShow(true);
                    monday_3.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    monday_3.setDate(calendar.getTime());
                    monday_3.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    monday_3.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        monday_3.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.TUESDAY) {
                    tuesday_3.setShow(true);
                    tuesday_3.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    tuesday_3.setDate(calendar.getTime());
                    tuesday_3.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    tuesday_3.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        tuesday_3.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.WEDNESDAY) {
                    wednesday_3.setShow(true);
                    wednesday_3.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    wednesday_3.setDate(calendar.getTime());
                    wednesday_3.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    wednesday_3.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        wednesday_3.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.THURSDAY) {
                    thursday_3.setShow(true);
                    thursday_3.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    thursday_3.setDate(calendar.getTime());
                    thursday_3.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    thursday_3.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        thursday_3.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.FRIDAY) {
                    friday_3.setShow(true);
                    friday_3.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    friday_3.setDate(calendar.getTime());
                    friday_3.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    friday_3.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        friday_3.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.SATURDAY) {
                    saturday_3.setShow(true);
                    saturday_3.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    saturday_3.setDate(calendar.getTime());
                    saturday_3.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    saturday_3.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        saturday_3.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.SUNDAY) {
                    sunday_3.setShow(true);
                    sunday_3.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    sunday_3.setDate(calendar.getTime());
                    sunday_3.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    sunday_3.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        sunday_3.setHasEntries(true);
                    }
                }
            }
            else if (weekOfMonth == 4) {
                int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
                if (dayOfWeek == Calendar.MONDAY) {
                    monday_4.setShow(true);
                    monday_4.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    monday_4.setDate(calendar.getTime());
                    monday_4.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    monday_4.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        monday_4.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.TUESDAY) {
                    tuesday_4.setShow(true);
                    tuesday_4.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    tuesday_4.setDate(calendar.getTime());
                    tuesday_4.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    tuesday_4.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        tuesday_4.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.WEDNESDAY) {
                    wednesday_4.setShow(true);
                    wednesday_4.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    wednesday_4.setDate(calendar.getTime());
                    wednesday_4.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    wednesday_4.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        wednesday_4.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.THURSDAY) {
                    thursday_4.setShow(true);
                    thursday_4.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    thursday_4.setDate(calendar.getTime());
                    thursday_4.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    thursday_4.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        thursday_4.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.FRIDAY) {
                    friday_4.setShow(true);
                    friday_4.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    friday_4.setDate(calendar.getTime());
                    friday_4.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    friday_4.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        friday_4.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.SATURDAY) {
                    saturday_4.setShow(true);
                    saturday_4.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    saturday_4.setDate(calendar.getTime());
                    saturday_4.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    saturday_4.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        saturday_4.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.SUNDAY) {
                    sunday_4.setShow(true);
                    sunday_4.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    sunday_4.setDate(calendar.getTime());
                    sunday_4.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    sunday_4.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        sunday_4.setHasEntries(true);
                    }
                }
            }
            else if (weekOfMonth == 5) {
                int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
                if (dayOfWeek == Calendar.MONDAY) {
                    monday_5.setShow(true);
                    monday_5.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    monday_5.setDate(calendar.getTime());
                    monday_5.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    monday_5.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        monday_5.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.TUESDAY) {
                    tuesday_5.setShow(true);
                    tuesday_5.setDate(calendar.getTime());
                    tuesday_5.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    tuesday_5.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    tuesday_5.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        tuesday_5.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.WEDNESDAY) {
                    wednesday_5.setShow(true);
                    wednesday_5.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    wednesday_5.setDate(calendar.getTime());
                    wednesday_5.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    wednesday_5.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        wednesday_5.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.THURSDAY) {
                    thursday_5.setShow(true);
                    thursday_5.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    thursday_5.setDate(calendar.getTime());
                    thursday_5.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    thursday_5.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        thursday_5.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.FRIDAY) {
                    friday_5.setShow(true);
                    friday_5.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    friday_5.setDate(calendar.getTime());
                    friday_5.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    friday_5.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        friday_5.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.SATURDAY) {
                    saturday_5.setShow(true);
                    saturday_5.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    saturday_5.setDate(calendar.getTime());
                    saturday_5.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    saturday_5.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        saturday_5.setHasEntries(true);
                    }
                }
                else if (dayOfWeek == Calendar.SUNDAY) {
                    sunday_5.setShow(true);
                    sunday_5.setToday(DateList.equals(calendar.getTime(), now.getTime(), false));
                    sunday_5.setDate(calendar.getTime());
                    sunday_5.setDisplay(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
                    sunday_5.setCalendarId(calendar.get(Calendar.DAY_OF_MONTH)+"_"+ MonthEnum.convert(calendar.get(Calendar.MONTH))+"_"+calendar.get(Calendar.YEAR));
                    if (datesWithBlogEntries.contains(calendar.getTime())) {
                        sunday_5.setHasEntries(true);
                    }
                }
            }

            calendar.add(Calendar.DAY_OF_MONTH, 1);
        }

        return new ForwardResolution(generateBlogThemePath(VIEW));
    }





    // == start getter setters ====

    public foo.bar.blog.web.action.Calendar getCalendar() {
        return calendar;
    }

    public void setCalendar(foo.bar.blog.web.action.Calendar calendar) {
        this.calendar = calendar;
    }

    public Blog getBlog() {
        return blog;
    }

    public void setBlog(Blog blog) {
        this.blog = blog;
    }

    public Day getMonday_1() {
        return monday_1;
    }

    public void setMonday_1(Day monday_1) {
        this.monday_1 = monday_1;
    }

    public Day getTuesday_1() {
        return tuesday_1;
    }

    public void setTuesday_1(Day tuesday_1) {
        this.tuesday_1 = tuesday_1;
    }

    public Day getWednesday_1() {
        return wednesday_1;
    }

    public void setWednesday_1(Day wednesday_1) {
        this.wednesday_1 = wednesday_1;
    }

    public Day getThursday_1() {
        return thursday_1;
    }

    public void setThursday_1(Day thursday_1) {
        this.thursday_1 = thursday_1;
    }

    public Day getFriday_1() {
        return friday_1;
    }

    public void setFriday_1(Day friday_1) {
        this.friday_1 = friday_1;
    }

    public Day getSaturday_1() {
        return saturday_1;
    }

    public void setSaturday_1(Day saturday_1) {
        this.saturday_1 = saturday_1;
    }

    public Day getSunday_1() {
        return sunday_1;
    }

    public void setSunday_1(Day sunday_1) {
        this.sunday_1 = sunday_1;
    }

    public Day getMonday_2() {
        return monday_2;
    }

    public void setMonday_2(Day monday_2) {
        this.monday_2 = monday_2;
    }

    public Day getTuesday_2() {
        return tuesday_2;
    }

    public void setTuesday_2(Day tuesday_2) {
        this.tuesday_2 = tuesday_2;
    }

    public Day getWednesday_2() {
        return wednesday_2;
    }

    public void setWednesday_2(Day wednesday_2) {
        this.wednesday_2 = wednesday_2;
    }

    public Day getThursday_2() {
        return thursday_2;
    }

    public void setThursday_2(Day thursday_2) {
        this.thursday_2 = thursday_2;
    }

    public Day getFriday_2() {
        return friday_2;
    }

    public void setFriday_2(Day friday_2) {
        this.friday_2 = friday_2;
    }

    public Day getSaturday_2() {
        return saturday_2;
    }

    public void setSaturday_2(Day saturday_2) {
        this.saturday_2 = saturday_2;
    }

    public Day getSunday_2() {
        return sunday_2;
    }

    public void setSunday_2(Day sunday_2) {
        this.sunday_2 = sunday_2;
    }

    public Day getMonday_3() {
        return monday_3;
    }

    public void setMonday_3(Day monday_3) {
        this.monday_3 = monday_3;
    }

    public Day getTuesday_3() {
        return tuesday_3;
    }

    public void setTuesday_3(Day tuesday_3) {
        this.tuesday_3 = tuesday_3;
    }

    public Day getWednesday_3() {
        return wednesday_3;
    }

    public void setWednesday_3(Day wednesday_3) {
        this.wednesday_3 = wednesday_3;
    }

    public Day getThursday_3() {
        return thursday_3;
    }

    public void setThursday_3(Day thursday_3) {
        this.thursday_3 = thursday_3;
    }

    public Day getFriday_3() {
        return friday_3;
    }

    public void setFriday_3(Day friday_3) {
        this.friday_3 = friday_3;
    }

    public Day getSaturday_3() {
        return saturday_3;
    }

    public void setSaturday_3(Day saturday_3) {
        this.saturday_3 = saturday_3;
    }

    public Day getSunday_3() {
        return sunday_3;
    }

    public void setSunday_3(Day sunday_3) {
        this.sunday_3 = sunday_3;
    }

    public Day getMonday_4() {
        return monday_4;
    }

    public void setMonday_4(Day monday_4) {
        this.monday_4 = monday_4;
    }

    public Day getTuesday_4() {
        return tuesday_4;
    }

    public void setTuesday_4(Day tuesday_4) {
        this.tuesday_4 = tuesday_4;
    }

    public Day getWednesday_4() {
        return wednesday_4;
    }

    public void setWednesday_4(Day wednesday_4) {
        this.wednesday_4 = wednesday_4;
    }

    public Day getThursday_4() {
        return thursday_4;
    }

    public void setThursday_4(Day thursday_4) {
        this.thursday_4 = thursday_4;
    }

    public Day getFriday_4() {
        return friday_4;
    }

    public void setFriday_4(Day friday_4) {
        this.friday_4 = friday_4;
    }

    public Day getSaturday_4() {
        return saturday_4;
    }

    public void setSaturday_4(Day saturday_4) {
        this.saturday_4 = saturday_4;
    }

    public Day getSunday_4() {
        return sunday_4;
    }

    public void setSunday_4(Day sunday_4) {
        this.sunday_4 = sunday_4;
    }

    public Day getMonday_5() {
        return monday_5;
    }

    public void setMonday_5(Day monday_5) {
        this.monday_5 = monday_5;
    }

    public Day getTuesday_5() {
        return tuesday_5;
    }

    public void setTuesday_5(Day tuesday_5) {
        this.tuesday_5 = tuesday_5;
    }

    public Day getWednesday_5() {
        return wednesday_5;
    }

    public void setWednesday_5(Day wednesday_5) {
        this.wednesday_5 = wednesday_5;
    }

    public Day getThursday_5() {
        return thursday_5;
    }

    public void setThursday_5(Day thursday_5) {
        this.thursday_5 = thursday_5;
    }

    public Day getFriday_5() {
        return friday_5;
    }

    public void setFriday_5(Day friday_5) {
        this.friday_5 = friday_5;
    }

    public Day getSaturday_5() {
        return saturday_5;
    }

    public void setSaturday_5(Day saturday_5) {
        this.saturday_5 = saturday_5;
    }

    public Day getSunday_5() {
        return sunday_5;
    }

    public void setSunday_5(Day sunday_5) {
        this.sunday_5 = sunday_5;
    }

    // == end getters setters ===























    @SpringBean("blogService")
    public void setBlogService(BlogService blogService) {
        this.blogService = blogService;    
    }


    public static class Day {

        private Date date;
        private boolean show = false;
        private String display;
        private boolean isToday = false;
        private boolean hasEntries = false;
        private String calendarId;


        public Date getDate() {
            return date;
        }

        public void setDate(Date date) {
            this.date = date;
        }


        public boolean isShow() {
            return show;
        }

        public void setShow(boolean show) {
            this.show = show;
        }

        public String getDisplay() {
            return display;
        }

        public void setDisplay(String display) {
            this.display = display;
        }

        public boolean isToday() {
            return isToday;
        }

        public void setToday(boolean today) {
            isToday = today;
        }

        public boolean isHasEntries() {
            return hasEntries;
        }

        public void setHasEntries(boolean hasEntries) {
            this.hasEntries = hasEntries;
        }

        public String getCalendarId() {
            return calendarId;
        }

        public void setCalendarId(String calendarId) {
            this.calendarId = calendarId;
        }
    }

}
